package com.blockmeta.bbs.businesslibrary.util.navigation.impl;

import android.net.Uri;
import android.text.TextUtils;

import com.blockmeta.bbs.businesslibrary.arouter.RouterPath;
import com.blockmeta.bbs.businesslibrary.constant.Constant;
import com.blockmeta.bbs.businesslibrary.util.navigation.SimpleDeepLinkStrategy;

import java.util.HashMap;
import java.util.Map;

/**
 * @author AirThor
 * @date 2019/7/24.
 */
public class NewsDetailStrategy extends SimpleDeepLinkStrategy {
    @Override
    public Uri uriTransformer(Uri uri) {
        if (TextUtils.isEmpty(uri.getQueryParameter("post_name"))&&TextUtils.isEmpty(uri.getQueryParameter("tid"))){
            return Uri.parse("blockmeta://news"+ RouterPath.WEB_ACTIVITY);
        }
        return Uri.parse("blockmeta://news"+ RouterPath.NEWS_INNER_DETAIL_ACTIVITY);
    }

    @Override
    public Map<String, String> navigationParams(Uri uri) {
        HashMap<String,String> params = new HashMap<>(4);
        if (!TextUtils.isEmpty(uri.getQueryParameter("post_name"))) {
            params.put(Constant.ZERO, uri.getQueryParameter("post_name"));
        }else if(!TextUtils.isEmpty(uri.getQueryParameter("tid"))) {
            params.put(Constant.ONE, uri.getQueryParameter("tid"));
        } else {
            params.put(Constant.ZERO,uri.getQueryParameter("source"));
        }
        return params;
    }
}
